//
//  BKMain_ClassifyViewCell.m
//  bestkeep
//
//  Created by yons on 16/11/18.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKMain_ClassifyViewCell.h"
#import "BKMainCommon.h"


@interface BKMain_ClassifyViewCell()
@property(nonatomic,strong)GoodsModel *goodsList;
@property (nonatomic,strong) UIImageView *CrossBorderAmoyImgView;//跨境淘
@end

@implementation BKMain_ClassifyViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
        [self addGestureRecognizer:tap];
        [self initViews];
    }
    return self;
}
-(void)tapAction{
    
//    BKMainViewController *mainPage  = (BKMainViewController *)self.nextResponder.nextResponder.nextResponder;
//    Mediator *mediator = [Mediator sharedInstance];
//    UIViewController *detailVC = [mediator BKGD_goodsDetailViewController:_goodsList.goodsId saleTypes:_goodsList.saleTypes];
//    detailVC.view.backgroundColor = [UIColor whiteColor];
//    [mainPage.navigationController pushViewController:detailVC animated:YES];

    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"HideNaviSearchNotion" object:@"BK_main_Hide"];
    CGRect goodsFrame = [self convertRect:self.goodsImageView.frame toView:self.superview.superview];
    BKMainViewController *mainPage  = (BKMainViewController *)self.nextResponder.nextResponder.nextResponder;
    [BKMainCommon goodsDetailAnimationWithFrame:goodsFrame goodsId:_goodsList.goodsId saleTypes:_goodsList.saleTypes goodsCoverImg:_goodsList.goodsCoverImg ViewController:mainPage];
    
}

-(void)initViews{
    
    _goodsView = [[UIView alloc] initWithFrame:self.bounds];
    [self addSubview:_goodsView];
    
    _goodsImageView = [UIImageView new];
    _goodsImageView.userInteractionEnabled = YES;
    [_goodsView addSubview:_goodsImageView];
    
    [_goodsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(14);
        make.left.equalTo(self.mas_left).offset(25);
        make.right.equalTo(self.mas_right).offset(-15);
        make.width.equalTo(_goodsImageView.mas_height);
    }];
    
    _goodsDetail = [UILabel new] ;
    _goodsDetail.textColor = RGBACOLOR(64, 64, 64, 1);
    _goodsDetail.font = [Common systemFontOfSize:14];
    _goodsDetail.textAlignment = NSTextAlignmentCenter;
    [_goodsView addSubview:_goodsDetail];
    
    [_goodsDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_goodsImageView.mas_bottom).offset(5);
        make.left.equalTo(self.mas_left).offset(10);
        make.right.equalTo(self.mas_right).offset(-10);
    }];
    
    _goodsPrice = [UILabel new];
    _goodsPrice.textColor = RGBACOLOR(255, 16, 16, 1);
    _goodsPrice.font = [Common systemFontOfSize:14];
    _goodsPrice.textAlignment = NSTextAlignmentCenter;
    [_goodsView addSubview:_goodsPrice];
    [_goodsPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_goodsDetail.mas_bottom).offset(5);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);

    }];
    
    //全球购标志
    
//    self.CrossBorderAmoyImgView = [[UIImageView alloc]init];
//    self.CrossBorderAmoyImgView.hidden = YES;
//    self.CrossBorderAmoyImgView.image = [UIImage imageNamed:@"BKMain_GlobalPurchase"];
//    [self.contentView addSubview:self.CrossBorderAmoyImgView];
//
//    [_CrossBorderAmoyImgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.top.mas_equalTo(self.goodsImageView.mas_bottom).offset(10);
//        make.left.mas_equalTo(self.mas_left).offset(10);
//        make.size.mas_equalTo(CGSizeMake(42, 15));
//    }];
}

- (void)fillData:(id)data{
    if (!data) {
        return;
    }
    
    _goodsList = [[GoodsModel alloc] init];
    [_goodsList setValuesForKeysWithDictionary:data];
    
    [_goodsImageView sd_setImageWithURL:[NSURL URLWithString:_goodsList.goodsCoverImg] placeholderImage:[UIImage imageNamed:@"BKMain_newGoods"]];
    _goodsDetail.text = _goodsList.goodsName;
    if (_goodsList.upText == nil) {
        _goodsList.upText = @"";
    }
    
    _goodsPrice.attributedText = [BKMainCommon specialStringStyle:[NSString stringWithFormat:@"%@%@", _goodsList.goodsPrice, _goodsList.upText] fontOfSize:10];
    
//    跨境淘
//    if ([_goodsList.channelType integerValue] == 2) {
//        self.CrossBorderAmoyImgView.hidden = NO;
//        [BKMainCommon setFirstLineTextIndentWithContent:self.goodsDetail firstLineHeadIndent:45];
//    }
//    
//    else
//    {
//        self.CrossBorderAmoyImgView.hidden = YES;
//        [BKMainCommon setFirstLineTextIndentWithContent:self.goodsDetail firstLineHeadIndent:0];
//    }
//
}

+(CGSize)calculateSize:(id)data{
    if(!data || ![data isKindOfClass:[NSDictionary class]]) {
        return CGSizeMake(0, 0);
    }
    if (SCREENWIDTH < 375) {
        return CGSizeMake(SCREENWIDTH / 3.f-0.01, 153*SCREENWIDTH/375.f + 10);
    }else{
        return CGSizeMake(SCREENWIDTH / 3.f-0.01, 153*SCREENWIDTH/375.f + 3);
    }
}

@end
